//封装请求页面加载的参数
function setPostData(){
    return {
        userNumber:$("#userNumber").val(),
        loginName:$("#loginName").val(),
        mobilePhone:$("#mobilePhone").val(),
        status:$("#status").val()

    };
}

//加载页面
$(document).ready(function () {

    var data_colNames = [
        'Id',
        '<div align="center"><span>员工编号</span></div>',
        '<div align="center"><span>登陆名</span></div>',
        '<div align="center"><span>真实名称</span></div>',
        '<div align="center"><span>性别</span></div>',
        '<div align="center"><span>生日</span></div>',
        '<div align="center"><span>移动电话号码</span></div>',
        '<div align="center"><span>入职时间</span></div>',
        '<div align="center"><span>上次登录时间</span></div>',
        '<div align="center"><span>总登录次数</span></div>',
        '<div align="center"><span>状态</span></div>',
        '<div align="center"><span>操作</span></div>'
    ];

    var data_colModel = [
        {name: 'id', index: 'id',hidden: true },
        {name: 'userNumber', index: 'userNumber', sortable: false, align: 'center', width: 100},
        {name: 'loginName',  index: 'loginName',  sortable: false, align: 'center', width: 90},
        {name: 'realName',   index: 'realName',   sortable: false, align: 'center', width: 50},
        {name: 'sex',        index: 'sex',        sortable: false, align: 'center', width: 100,
            formatter: function (x) {return storeStatusTransformViewData(sex_status, x);}
        },
        {name: 'birthday',   index: 'birthday',    sortable: false, align: 'center', width: 100,
            formatter: function (x) {return changeDateFormat(x);}
        },
        {name: 'mobilePhone',index: 'mobilePhone', sortable: false, align: 'center', width: 50},
        {name: 'joinTime',   index: 'joinTime',    sortable: false, align: 'center', width: 100,
            formatter: function (x) {return changeDateFormat(x);}
        },
        {name: 'lastLogin',  index: 'lastLogin',   sortable: false, align: 'center', width: 100,
            formatter: function (x) {return changeDateFormat(x);}
        },
        {name: 'sumLogin',   index: 'sumLogin',    sortable: false, align: 'center', width: 50},
        {name: 'status',     index: 'status',      sortable: false, align: 'center', width: 100,
            formatter: function (x) {return storeStatusTransformViewData(general_status, x);}
        },

        {name: 'id', index: 'id', sortable: false, resizable: false, align: 'center', width: 100,
            formatter: function (x,y,z) {
                return '<a class="btn btn-primary btn-xs" onclick="generalUpdate(\''+x+'\');">修改</a> ' +
                    '<a class="btn btn-primary btn-xs" onclick="generalDelete(\''+x+'\',\''+z['systemName']+'\');">删除</a>';
            }
        }

];

    initJqgrid(url_config.boss_user_list,data_colNames,data_colModel);
});




//查询
$("#generalQuery").bind('click',function(){
    var reloadParams = {
        url: url_config.boss_user_list,
        postData: setPostData()
    };
    jqgrid_reload(reloadParams);
});

//刷新页面
function reload(){
    var reloadParams = {
        url: url_config.boss_user_list,
        postData: setPostData()
    };
    jqgrid_reload(reloadParams);
}


$("#generalExport").bind('click',function () {
    $('<form method="post" action="' + sysUser_download_url + '">' +
        '<input name="loginName" value="'+setPostData().loginName+'"/>' +
        '<input name="realName" value="'+setPostData().realName+'"/>' +
        '<input name="phone" value="'+setPostData().phone+'"></form>')
        .appendTo('body').submit().remove();
});


//新增
$("#generalAdd").bind('click',function(){
    openPage(url_config.gateway_business_system_add_page,'新增业务系统');
});
function generalUpdate(id){
    openPage(url_config.gateway_business_system_add_page +"?id="+id,'修改业务系统');

}

function openPage(requestUrl,openPateType){
    parent.layer.open({
        type: 2,
        title: openPateType,
        shadeClose: true,
        shade: [0.5],
        maxmin: false, //开启最大化最小化按钮
        area: ['768px', '600px'],
        content: requestUrl,
        end: function () {
            reload();
        },
        success: function(layero, index) {
            layer.iframeAuto(index);
        }
    });
}



//删除用户
function generalDelete(id, sysUserName) {

    layer.confirm('确定要删除应用系统:' + sysUserName, {
        btn: ['确定', '取消'] //按钮
    }, function () {
        $.ajax({
            url: url_config.gateway_business_delete,
            type: 'POST',
            dataType: 'json',
            data: {id:id}
        })
            .done(function (result) {
                serviceValidateHandleCurrent(result,true,true);
                reload();
            });
    }, function () {
        parent.layer.closeAll('iframe');
    });

}

